<ul class="nav nav-tabs" id="tabs">
    <li class="active"><a href="#league" data-toggle="tab">Tabela</a></li>
    <li><a href="#games" data-toggle="tab">Terminarz</a></li>
    <li><a href="#stats" data-toggle="tab">Statystyki</a></li>
</ul>
<div class="tab-content">
    <div id="league" class="tab-pane active">
        <h2>Tabela</h2>
        <table id="table-league" class="no-gutter table table-striped table-condensed tablesorter span8">
            <thead>
                <tr>
                    <th>Lp.</th>
                    <th class="large">Nazwa</th>
                    <th class="tiny">Mecze</th>
                    <th class="tiny">Punkty</th>
                    <th class="tiny"><abbr title="Zwycięstwa - Remisy - Porażki">Z-R-P</abbr></th>
                    <th class="tiny">Zdobyte</th>
                    <th class="tiny">Stracone</th>
                    <th class="tiny">Różnica</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $i=1;
                foreach($teams['comp'] as $wynik)
                    foreach($wynik['league'] as $w)
                    {
                        foreach($w['teams'] as $tk=>$tv)
                        {
                            $sort_points[]  = $tv['points'];
                            $sort_goaldiff[]= $tv['goal_for']-$tv['goal_against'];
                        }
                        array_multisort($sort_points,SORT_DESC,$sort_goaldiff,SORT_DESC,$w['teams']);
                        foreach($w['teams'] as $t)
                        {
                            $wins   = !empty($t['wins']) ? $t['wins'] : 0;
                            $draws  = !empty($t['draws']) ? $t['draws'] : 0;
                            $loses  = !empty($t['loses']) ? $t['loses'] : 0;
                            echo '<tr>'
                                    .'<td>'.$i.'</td>'
                                    .'<td>'.($t['id']==$this->config->item('ut_team') ? '<strong>'.$t['name'].'</strong>' : $t['name']).'</td>'
                                    .'<td>'.$t['played'].'</td>'
                                    .'<td>'.$t['points'].'</td>'
                                    .'<td>'.$wins.'-'.$draws.'-'.$loses.'</td>'
                                    .'<td>'.$t['goalfor'].'</td>'
                                    .'<td>'.$t['goalaga'].'</td>'
                                    .'<td>'.($t['goalfor']-$t['goalaga']).'</td>'
                                .'</tr>';
                            $i++;
                        }
                    }
                ?>
            </tbody>
        </table>
    </div>
    <div id="games" class="tab-pane <?php echo ($editor ? 'span5' : 'span4'); ?>">
        <h2>Terminarz</h2>
        <?php foreach($score as $ki=>$kol): ?>
        <table class="fixture table table-striped table-condensed">
            <thead>
                <?php if($editor): ?>
                <tr>
                    <td colspan="5">
                        <?php echo ($editor ? anchor('league/edit_fixture/'.$ki.'/'.$this->config->item('ut_liga').'/'.$sezon,'Edytuj kolejkę',array('class'=>'btn btn-danger btn-mini right')) : ''); ?>
                    </td>
                </tr>
                <?php endif; ?>
                <tr>
                    <th>Godz.</th>
                    <th><abbr title="Gospodarz">Gosp.</abbr></th>
                    <th>Wynik</th>
                    <th>Gość</th>
                    <?php echo ($editor ? '<td></td>' : ''); ?>
                </tr>
            </thead>
            <?php
            $i=1;
            foreach($kol as $gi=>$game)
            {
                if($i==1)
                {
                    echo '<caption class="label">Kolejka '.$ki.' - '.date('d.m.Y',$game['date']).'</caption>';
                    echo '<tbody>';
                }
                echo '<tr>'
                        .'<td class="span1 no-gutter">'.$game['hour'].'</td>'
                        .'<td class="span1 no-gutter"><abbr title="'.$game['gosp']['name'].'">'.$game['gosp']['code'].'</abbr></td>'
                        .'<td class="span1 no-gutter">'.$game['gosp']['goals'].' - '.$game['gosc']['goals'].'</td>'
                        .'<td class="span1 no-gutter"><abbr title="'.$game['gosc']['name'].'">'.$game['gosc']['code'].'</abbr></td>';
                if($editor)
                    echo '<td class="span1 no-gutter">'.anchor('league/edit_game/'.$gi,'Edytuj mecz',array('class'=>'btn btn-primary btn-mini')).'</td>';
                echo '</tr>';
                if($i==count($kol))
                    echo '</tbody>';
            }
            ?>
        </table>
        <?php endforeach; ?>
    </div>
    <div id="stats" class="tab-pane">
        <h2>Statystyki</h2>
    </div>
</div>
